﻿package morn.core.utils
{
    import flash.display.*;
    import flash.filters.*;
    import flash.text.*;
    import flash.utils.*;

    public class ObjectUtils extends Object
    {
        private static const grayFilter:ColorMatrixFilter = new ColorMatrixFilter([0.3086, 0.6094, 0.082, 0, 0, 0.3086, 0.6094, 0.082, 0, 0, 0.3086, 0.6094, 0.082, 0, 0, 0, 0, 0, 1, 0]);
        private static var _tf:TextField = new TextField();

        public function ObjectUtils()
        {
            return;
        }// end function

        public static function addFilter(param1:DisplayObject, param2:BitmapFilter) : void
        {
            var _loc_3:* = param1.filters || [];
            _loc_3.push(param2);
            param1.filters = _loc_3;
            return;
        }// end function

        public static function clearFilter(param1:DisplayObject, param2:Class) : void
        {
            var _loc_4:int = 0;
            var _loc_5:* = undefined;
            var _loc_3:* = param1.filters;
            if (_loc_3 != null && _loc_3.length > 0)
            {
                _loc_4 = _loc_3.length - 1;
                while (_loc_4 > -1)
                {
                    
                    _loc_5 = _loc_3[_loc_4];
                    if (_loc_5 is param2)
                    {
                        _loc_3.splice(_loc_4, 1);
                    }
                    _loc_4 = _loc_4 - 1;
                }
                param1.filters = _loc_3;
            }
            return;
        }// end function

        public static function clone(param1)
        {
            var _loc_2:* = new ByteArray();
            _loc_2.writeObject(param1);
            _loc_2.position = 0;
            return _loc_2.readObject();
        }// end function

        public static function createBitmap(param1:int, param2:int, param3:uint = 0, param4:Number = 1) : Bitmap
        {
            var _loc_5:* = new Bitmap(new BitmapData(1, 1, false, param3));
            new Bitmap(new BitmapData(1, 1, false, param3)).alpha = param4;
            _loc_5.width = param1;
            _loc_5.height = param2;
            return _loc_5;
        }// end function

        public static function readAMF(param1:ByteArray) : Object
        {
            if (param1 && param1.length > 0 && param1.readByte() == 17)
            {
                return param1.readObject();
            }
            return null;
        }// end function

        public static function writeAMF(param1:Object) : ByteArray
        {
            var _loc_2:* = new ByteArray();
            _loc_2.writeByte(17);
            _loc_2.writeObject(param1);
            return _loc_2;
        }// end function

        public static function gray(param1:DisplayObject, param2:Boolean = true) : void
        {
            if (param2)
            {
                addFilter(param1, grayFilter);
            }
            else
            {
                clearFilter(param1, ColorMatrixFilter);
            }
            return;
        }// end function

        public static function getTextField(param1:TextFormat, param2:String = "Test") : TextField
        {
            _tf.autoSize = "left";
            _tf.defaultTextFormat = param1;
            _tf.text = param2;
            return _tf;
        }// end function

    }
}
